// pages/user/user.js
var App = getApp();
function jsonSort(jsonObj) {
    let arr = [];
    for (var key in jsonObj) {
        arr.push(key)
    }
    arr.sort();
    let str = '';
    for (var i in arr) {
        str += arr[i] + "=" + jsonObj[arr[i]] + "&"
    }
    return str.substr(0, str.length - 1)
}

Page({

    /**
     * 页面的初始数据
     */
    data: {
        store_name: [],//店铺的数据
        appointment_list: [],
        index_data: [],
        level: 1,
        store_list: [],
        index: 0,
        course_id:'',//
        see_information:1,
        
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.onLoad();
    },
    onLoad: function (options) {
        var This = this;
        console.log(wx.getStorageSync('openid'))
        console.log(wx.getStorageSync('phone'))
        if (wx.getStorageSync('openid') == '') {
            wx.reLaunch({
                url: '/pages/phone_login/phone_login',
            })
            return false;
        } else if (wx.getStorageSync('phone') == '') {
            wx.reLaunch({
                url: '/pages/phone_login/phone_login',
            })
            return false;
        }
        This.loading();
        This.make_an_appointment();
        This.setData({
            level: wx.getStorageSync('level'),
            store_list: wx.getStorageSync('store'),
        })
        wx.setStorageSync('store_id', This.data.store_list[0].id)
        var store = [];
        for (var i = 0; i < wx.getStorageSync('store').length; i++) {
            store.push(wx.getStorageSync('store')[i].store_name)
        }
        This.setData({
            store_name: store
        })
        This.get_crouse_num();
        This.getIformation();
    },
    // 获取课程安排数量的接口
    get_crouse_num:function(){
        var This = this;
        App._get('coach/Coursearrange/indexCourse', {
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
        }, function (res) {
            if (res.status == 1) {
                This.setData({
                    see_information: res.no_sign_count
                })
            } else {
                wx.showToast({
                    title: res.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    // 消息列表
    getIformation(){
        var This = this;
        App._get('coach/Callerdetail/get_read_status', {
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
        }, function (res) {
            if (res.status == 1) {
                This.setData({
                    course_id: res.read_status
                })
            } else {
                wx.showToast({
                    title: res.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    bindPickerChange(e) {
        var This = this;
        This.setData({
            index: e.detail.value
        })
        wx.setStorageSync('store_id', This.data.store_list[This.data.index].id)
    },
    information: function () {
        wx.navigateTo({
            url: '/pages/information/information',
        })
    },
    /*预约联系详情页面*/
    appointment_phone(e) {
        wx.navigateTo({
            url: '/pages/filtrate/filtrate?type=1',
        })
    },
    /*今日入场普通会员*/
    sigin: function (e) {
        wx.navigateTo({
            url: '/pages/sigin/sigin',
        })
    },
    /*今日新增普通会员*/
    customer: function (e) {
        wx.navigateTo({
            url: '/pages/customer/customer',
        })
    },
    /* 今日入场私教会员*/
    new_vip(e) {
        wx.navigateTo({
            url: '/pages/private_church_members/private_church_members',
        })
    },
    /* 今日新增私教会员 */
    maintain_customer(e) {
        wx.navigateTo({
            url: '/pages/ready_prviatr_coach/ready_prviatr_coach',
        })
    },
    /**长时间未上课会员 */
    expiring_member(e) {
        wx.navigateTo({
            url: '/pages/long_absence_class/long_absence_class',
        })
    },
    //课程即将结束会员
    expiring_members(e) {
        wx.navigateTo({
            url: '/pages/end_course/end_course',
        })
    },
    //今日预约课时
    long_time_caller() {
        wx.navigateTo({
            url: '/pages/appointment_today/appointment_today',
        })
    },
    //今日消耗课时
    long_time_member() {
        wx.navigateTo({
            url: '/pages/consumption_today/consumption_today',
        })
    },
    // 预约来访显示
    make_an_appointment() {
        var This = this;
        // 预约接口
        App._get('coach/Callerdetail/get_reservation_contact', {
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            // store_id: 53,
            // openid: 1,
            // phone: 15612340001,
        }, function (res) {
            if (res.status == 1) {
                This.setData({
                    appointment_list: res.list
                })
            } else {
                wx.showToast({
                    title: res.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    //预约提醒 查看全部
    look_all: function () {
        wx.navigateTo({
            url: '/pages/filtrate/filtrate?type=0',
        })
    },
    // 工作提醒
    loading: function () {
        var This = this;
        App._get('coach/index/get_work_reminder', {
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
        }, function (res) {
            if (res.status == 1) {
                This.setData({
                    index_data: res.list
                })
            } else {
                wx.showToast({
                    title: res.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    //预约到店和联系打电话
    call_phone: function (e) {
        wx.makePhoneCall({
            phoneNumber: e.target.id,
        })
    },
    month_detail() {
        var This = this;
        var level = wx.getStorageSync('level')
        // var level = 3
        if (level == 3 || level == 2) {
            wx.navigateTo({
                url: '/pages/month_results/month_results',
            })
        }else if (level == 1) {
            wx.navigateTo({
                url: '/pages/month_results_pt/month_results_pt',
            })
        }
    },
    //潜客详情
    vc_detail(e) {
        console.log(e)
        // wx.navigateTo({
        //     url: '/pages/latent_maintenance/latent_maintenance?id=' + e.currentTarget.id + '&type=' + e.currentTarget.status,
        // })
    },
    /** 
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})